package com.panfeng.xcloud.common.security.config;

import com.panfeng.xcloud.common.core.component.SnowflakeIdWorker;
import com.panfeng.xcloud.common.core.properties.SnowflakeProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *
 * 雪花算法配置类
 *
 * @author xiaobo
 * @version 1.0
 * @since 2018-12-28
 */
@Configuration
@EnableConfigurationProperties({SnowflakeProperties.class})
public class SnowflakeConfiguration{

    @Autowired
    private SnowflakeProperties snowflakeProperties;

    @Bean
    @ConditionalOnMissingBean
    public SnowflakeIdWorker snowflakeIdWorker() {
        return new SnowflakeIdWorker(snowflakeProperties.getWorkerId(), snowflakeProperties.getDatacenterId());
    }
}
